//
var javaPath = "http://127.0.0.1:9999/ueditor/";
function generateSid(callback) {
   
    var postData = {
            Code: "XBYL"
        },
        xSid;

    

    return xSid
}

function generateSid1(callback) {
    
    var postData = {
            Code: "XBYL"
        },
        xSid;

  

    return xSid
}

function getData(xCode, xGUID, xPars, callback, isAsync, isCache) {
   
}

function setInputFocus(inputID) {
    $("#" + inputID).focus();
}

function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

function disableBackspacekeyboard() {
    document.onkeydown = function(e) {
        var ev = document.all ? window.event : e;
        if (ev.keyCode == 8) {
            if ($(':focus').length < 1) {
                window.event.returnValue = false;
            }
        }
    }
}

function disableF5keyboard() {
    document.onkeydown = function(e) {
        var ev = document.all ? window.event : e;
        if (ev.keyCode == 116) {
            if (confirm('Are you sure you want to exit?')) {
                window.top.location.href = 'home.html';
            }
            return false;
        }
    }
}

function isEmptyObject(obj) {
    for (var key in obj) {
        return false
    };
    return true
};

function UploadFile(formData,FileController,successCallback) {
         
          var xhr = new XMLHttpRequest();
          xhr.open("post", FileController, false);
          xhr.onload = function (data) {
            
              successCallback(JSON.parse(JSON.parse(data.target.response)));
          };
          xhr.send(formData);

          xhr.upload.addEventListener("progress", progressFunction, false);
        }
     
function progressFunction(evt) {
 
  if (evt.lengthComputable) {
    if(evt.loaded==evt.total){
        
      
    }
  }
} 

function setTransform(obj,value){
    obj.css({
        "transform" : value,
        "-webkit-transform" : value,
        "-moz-transform" : value,
        "-ms-transform" : value,
        "-o-transform" : value
        });
}

function getEvent(event){
    return (event || window.event);
}

function shiftPercent(num,ele){
    var maxw=375,desw = 750;

    if(ele ){
        maxw = ele.parent().width();
    }

    return (parseInt(num)/maxw*100)+"%";
}


function setPageHeight(maxHeight){
    maxHeight = maxHeight ? maxHeight : $(window).height();
    $(".xbyl-page-content").css("height",maxHeight-$(".xbyl-page-top").height()-$(".xbyl-page-bottom").height());
}

function watchJSON(){
    
}

function getSourceData(callback){
    getBlog(callback);
}

    
function getBlog(callback){
    
    $.ajax({
        type : "post",
        url  : javaPath+"blog/getBolg",
        dataType : "JSON",
        success : function(data){
            var res = JSON.parse(data),d = res.data;
           callback(d);
        }
    });
};

function getDataSourceList(callback){
    var temp=["<li class='mast dataSource' for='.dataSourceBox'><label>dataSource</label><ul class='childItemBox sourceNameList'><li><label>getFlight</label></li><li>blog</li></ul></li>"];
       //tempbox.push('<div class="contextItem dataSourceBox"> <div class="checkAll"><label class="checkText"><input type="checkBox"><span>全选</span></label></div> <ul class="xbyl-fieldList"> </ul> <div class="panelScroll"> <div class="scrollSilder"></div> </div> </div>')
        $(".pagePanelBox").find(".panelTitle").html("dataSourceList");
        $(".pagePanelBox").find(".panelContext").html(
        '<div class="contextItem dataSourceBox blog">'+
                        '<div class="checkAll"><label class="checkText"><input type="checkBox"><span>全选</span></label></div>'+
                        '<ul class="xbyl-fieldList">'+
                            
                        '</ul>'+
                        '<div class="panelScroll">'+
                            '<div class="scrollSilder"></div>'+
                        '</div>'+
                    '</div>');
        $(".pagePanelBox").find(".panelNavList").html("<li for='.blog' data-path='"+javaPath+"blog/getBolg'>blog</li><li></li>");
                                                
        callback ? callback() : "";
        showPagelBox();
        
}

function blogBack(d,callback){
    var fti= ['text','img','child'];
    var liTemp =[],fieldType = '<select style="width:100px;outline:none">';

    for(var i = 0; i < fti.length; i++ ){
        fieldType+='<option value="'+fti[i]+'">'+fti[i]+'</option>';
    }
    fieldType+='</select>';
    bd = d[0];
    for(var i in bd){
        liTemp.push('<li class="fieldItem '+i+'"><label class="fieldText"><span>'+i+'</span></label> <div class="fieldType">'+fieldType+'</div><div class="titleSwitch"><div class="radioList"> <div class="radioItem"> <input type="radio" name="'+i+'" value="YES" checked=""> <div class="radioText showText ">YES</div> </div> <div class="radioItem"> <input type="radio" name="'+i+'" value="NO" checked> <div class="radioText hideText ">NO</div> </div> </div></div><div class="fieldTitleText" style="display:none"><input value="'+i+'" placeholder="fieldTitle"/></div></li>');
    }

    $(".dataSourceBox .xbyl-fieldList").html(liTemp.join(""));
    callback ? callback() : "";
    $(".titleSwitch .radioItem input").change(function(){
        var v = $(this).val(),n = $(this).closest(".titleSwitch").next();
        if(v == "NO"){
            n.hide();
        }else{
            n.show();
        }
    });

    $(".dataSourceBox .fieldItem").click(function(){
        var $t = $(this);
        if($t.hasClass("selectedFieldItem")){
            $t.removeClass("selectedFieldItem");
        }else{
            $t.addClass("selectedFieldItem");
        }
    });

    return bd;
   }

function showPagelBox(){
    $(".xbyl-mask").show();
    $(".pagePanelBox").show(400);
}
function getColorPan(obj,callBack){
    obj.spectrum({
         //flat     : true,
         showAlpha: true,
         showPalette: true,
         showInput: true,
         showInitial: true,
         hideAfterPaletteSelect : true,
         color: 'blanchedalmond',
         preferredFormat : "hex",
         palette: [
            ["#000","#444","#666","#999","#ccc","#eee","#f3f3f3","#fff"],
            ["#f00","#f90","#ff0","#0f0","#0ff","#00f","#90f","#f0f"],
            ["#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#cfe2f3","#d9d2e9","#ead1dc"],
            ["#ea9999","#f9cb9c","#ffe599","#b6d7a8","#a2c4c9","#9fc5e8","#b4a7d6","#d5a6bd"],
            ["#e06666","#f6b26b","#ffd966","#93c47d","#76a5af","#6fa8dc","#8e7cc3","#c27ba0"],
            ["#c00","#e69138","#f1c232","#6aa84f","#45818e","#3d85c6","#674ea7","#a64d79"],
            ["#900","#b45f06","#bf9000","#38761d","#134f5c","#0b5394","#351c75","#741b47"],
            ["#600","#783f04","#7f6000","#274e13","#0c343d","#073763","#20124d","#4c1130"]
        ],

        change : function(color){
            callBack(color.toHslString());
        },
        move : function(color){
            callBack(color.toHslString());
        },

        dragstop : function(color){
            
        }
    });
}

function getFieldHTML(){
    
}

 






function setdefalutValue(tableGUID,field){
    $("[data-tableguid='"+tableGUID+"'] [data-guid='"+field["xGUID"]+"'] input").val(field["xDefault"]);
}
var tableInput = {
    "string" : function(tableGUID,field){

    },

    "boolean" : function(tableGUID,field){

    },

    "date" : function (tableGUID,field){
         new MobileSelect({
            trigger : "[data-tableguid='"+tableGUID+"'] [data-guid='"+field["xGUID"]+"'] input",
            title : field.xCaption,
            wheels : [
                {data : [2010,2011,2013,2014,2015,2016]},
                {data : [1,2,3,4,5,6,7,8,9,10,11,12]},
                {data : [1,2,3,4,5,6,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]},
                {data : [0,1,2,3,4,5,6,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]},
                {data : [0,1,2,3,4,5,6,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,21,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59]},
                {data : [0,1,2,3,4,5,6,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,21,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59]},
            ],
            /*keyMap : {
                value : field.xLookupFieldName,
                id    : field.xLookupFieldName
            }*/
        });
    },

    "file" :function(tableGUID,field){

    },

    "image" : function(tableGUID,field){

    },
    "lookup" : function(tableGUID,field){
        GetLookupData(tableGUID,field.xName,JSON.stringify(GetData(tableGUID)));

        new MobileSelect({
            trigger : "[data-tableguid='"+tableGUID+"'] [data-guid='"+field["xGUID"]+"'] input",
            title : field.xCaption,
            wheels : [
                {data : [1,2,3,4,5,6]}
            ],
            /*keyMap : {
                value : field.xLookupFieldName,
                id    : field.xLookupFieldName
            }*/
        });
    },
    "radio" : function(tableGUID,field){

    }
}

function initTableItem(tableGUID){
   
}

var HEX = {
        0  : "00",
        1  : "01",
        2  : "02",
        3  : "03",
        4  : "04",
        5  : "05",
        6  : "06",
        7  : "07",
        8  : "08",
        9  : "09",
        10 : "0a",
        11 : "0b",
        12 : "0c",
        13 : "0d",
        14 : "0e",
        15 : "0f"
  };